import Conf from "@/config/form"
const ISTYPE = Object.prototype.toString;

//
function Valid(){
  this.map = {};
}

Valid.prototype.add = function (key = '',value) {
  this.map[key] = value;
}

Valid.prototype.formatRules = function (opt = {}) {
  for(let key in opt){
    let arr = opt[key];
    let res = [];
    if(ISTYPE.call(arr) == "[object Array]"){
      arr.forEach((item)=>{
        if(ISTYPE.call(item) == "[object String]"){
          item = {name:item}
        }
        //
        let mapValue = this.map[item.name] || {};
        res.push({ trigger: "blur" ,...mapValue,...item});
      })
    }
    opt[key] = res;
  }
  return opt;
}

let inst = new Valid();
Conf(inst);
export default inst;

